import 'package:carousel_slider/carousel_slider.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:industry_net/base/common/util.dart';

import 'index.dart';

class WelcomePage extends GetView<WelcomeController> {
  const WelcomePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final state = controller.state;
    final _list = state.list ?? [];
    return GetBuilder<WelcomeController>(
      builder: (_) {
        return Scaffold(
          body: _list.isEmpty
              ? null
              : Stack(
                  children: [
                    PageView.builder(
                      controller: state.pageCtrl,
                      itemCount: _list.length,
                      itemBuilder: (_, index) {
                        return loadImage(
                            url: _list[index].url,
                            width: Get.width,
                            height: Get.height);
                      },
                      onPageChanged: (value) {
                        state.currentIndex.value = value;
                      },
                    ),
                    Obx(
                      () => Positioned(
                        bottom: SizeFit.safeBottom + 30.h,
                        width: Get.width,
                        child: state.currentIndex.value == _list.length - 1
                            ? Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  InkWell(
                                    onTap: controller.toMain,
                                    child: Container(
                                      width: 60.r,
                                      height: 36.r,
                                      alignment: Alignment.center,
                                      decoration: BoxDecoration(
                                        color: ColorsUtil.green,
                                        borderRadius:
                                            BorderRadius.circular(circle4),
                                      ),
                                      child: Text(
                                        '进入',
                                        style: pfMediumStyle(
                                            color: ColorsUtil.white,
                                            fontSize: font13),
                                      ),
                                    ),
                                  ),
                                ],
                              )
                            : Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: _list
                                    .asMap()
                                    .map(
                                      (index, e) => MapEntry(
                                        index,
                                        Container(
                                          width: 8.r,
                                          height: 8.r,
                                          margin: const EdgeInsets.symmetric(
                                              horizontal: 3),
                                          decoration: BoxDecoration(
                                              color: index ==
                                                      state.currentIndex.value
                                                  ? ColorsUtil.white
                                                  : const Color(0x66ffffff),
                                              borderRadius:
                                                  BorderRadius.circular(4.r)),
                                        ),
                                      ),
                                    )
                                    .values
                                    .toList(),
                              ),
                      ),
                    ),
                  ],
                ),
        );
      },
    );
  }
}
